package fr.cephb.joperon.webapp.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class TR extends BodyTagSupport
	{
	private static final long serialVersionUID = 1L;
	private static final String ROW_NUMBER= "tr-row-number-for-styling";
	public TR()
		{
		}

	@Override
	public int doStartTag() throws JspException
		{
		try {
			Integer row= Integer.class.cast(pageContext.getAttribute(ROW_NUMBER, PageContext.PAGE_SCOPE));
			row=(row==null || row==1?0:1);
			pageContext.setAttribute(ROW_NUMBER, row);
			super.pageContext.getOut().print("<tr class=\"row"+(row%2)+"\">");
			} 
		catch (IOException e)
			{
			throw new JspException(e);
			}
		return EVAL_BODY_INCLUDE;
		}

	@Override
	public int doEndTag() throws JspException {
		try {
			super.pageContext.getOut().print("</tr>");
			} 
		catch (IOException err)
			{
			throw new JspException(err);
			}
		return EVAL_PAGE;
		}


}
